# Maintainer:  Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Contributor: carstene1ns <url/mail: arch carsten-teibes de>
# Contributor: Tai Chi Minh Ralph Eastwood <tcmreastwood@gmail.com>


_realname=physfs
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-hg
pkgver=r1345.29ab417d9453
pkgrel=2
pkgdesc="A library to provide abstract access to various archives (development version)"
arch=('any')
url="http://icculus.org/physfs/"
license=('zlib')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             'doxygen'
             'mercurial')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
source=("hg+http://hg.icculus.org/icculus/physfs"
        "0000_pkgconfig.patch")
md5sums=('SKIP'
         'b6cc4cff5283805638566f2e8ae3b13f')

pkgver() {
  cd ${srcdir}/${_realname}
  printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -Np1 -i ${srcdir}/0000_pkgconfig.patch

  # avoid abort in docs target
  sed -i 's/-Werror//' CMakeLists.txt
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  #pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  #export PREFIX_WIN=`pwd -W`
  #popd > /dev/null

  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DPHYSFS_BUILD_TEST=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DPHYSFS_BUILD_WX_TEST=OFF ${srcdir}/${_realname}
  make all
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  make install

  install -Dm644 ${srcdir}/${_realname}/LICENSE.txt \
    "$pkgdir"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/physfs.pc
}
